package cn.wolfcode.crm.web.controller;


import cn.wolfcode.crm.domain.ClientRecord;
import cn.wolfcode.crm.query.ClientRecordObjectQuery;
import cn.wolfcode.crm.query.PageResult;
import cn.wolfcode.crm.service.IClientRecordService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("clientRecord")
public class ClientRecordController {
    @Autowired
    private IClientRecordService clientRecordService;

    //客户转移列表
    @RequiresPermissions("clientRecord:transferList")
    @PermissionName("客户转移记录列表")
    @RequestMapping("/transfer")
    public String transferList() {

        return "clientRecord/transferList";
    }

    //客户流失列表
    @RequiresPermissions("clientRecord:lossList")
    @PermissionName("客户流失记录列表")
    @RequestMapping("/loss")
    public String lossList(Model model) {
        model.addAttribute("queryForStatus",0);
        return "clientRecord/oderList";
    }


    //客户开发成功列表
    @RequiresPermissions("clientRecord:developmentSuccess")
    @PermissionName("客户开发成功记录列表")
    @RequestMapping("/developmentSuccess")
    public String developmentSuccess(Model model) {
        model.addAttribute("queryForStatus",2);
        return "clientRecord/oderList";
    }


    //客户开发失败列表
    @RequiresPermissions("clientRecord:developmentOfFailure")
    @PermissionName("客户开发失败记录列表")
    @RequestMapping("/developmentOfFailure")
    public String developmentOfFailure(Model model) {
        model.addAttribute("queryForStatus",3);
        return "clientRecord/oderList";
    }


    @RequiresPermissions("clientRecord:index")
    @PermissionName("客户记录列表主页")
    @RequestMapping("list")
    @ResponseBody
    public PageResult list(Model model, @ModelAttribute("qo") ClientRecordObjectQuery qo) {
//        List<ClientRecord> list = clientRecordService.getAll();
        PageResult<ClientRecord> list = clientRecordService.query(qo);
        return list;
    }







    @RequiresPermissions("clientRecord:save")
    @PermissionName("客户记录创建")
    @RequestMapping("save")
    @ResponseBody
    public JsonResult save(ClientRecord clientRecord) {
        JsonResult jsonResult = new JsonResult();
        try {

                clientRecordService.save(clientRecord);

        } catch (Exception e) {
            e.printStackTrace();
            jsonResult.markErrorMsg("保存客户记录失败");
        }
        return jsonResult;
    }


}
